package com.sls.web.manager.action.recharge;

import javax.annotation.Resource;

import com.sls.web.manager.common.Constants;
import com.sls.web.manager.page.Pagination;
import com.sls.web.manager.recharge.pojo.Orders;
import com.sls.web.manager.recharge.querybean.OrdersQuery;
import com.sls.web.manager.recharge.service.OrdersService;

public class OrdersAction extends SupplierAction {
	private static final long serialVersionUID = 1L;
	@Resource(name = "ordersService")
	private OrdersService ordersService;
	private Pagination<Orders> page;
	private OrdersQuery ordersQuery;
	private Orders orders;
	private Boolean editPay;

	public String ordersList() {
		try {
			if (ordersQuery == null) {
				ordersQuery = new OrdersQuery();
				ordersQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
				ordersQuery.setPageSize(Constants.INIT_PAGESIZE);
			}
			page = ordersService.findNotPay(ordersQuery, getCurrentOperator());

		} catch (Exception e) {
			addActionError(e.getMessage());
		}
		return "list";
	}

	public String edit() {
		try {
			orders = ordersService.findById(orders, getCurrentOperator());
		} catch (Exception e) {
			addActionError(e.getMessage());
		}
		return "edit";
	}

	public String manual() {
		try {
			if (editPay && orders.getPay()) {
				orders.setStatus(Constants.ORDERS_PAY);
			} else if ((!editPay) && orders.getOrderSuccess()) {
				orders.setStatus(Constants.ORDERS_SUCCESS);
			} else {
				throw new RuntimeException("修改信息格式有误...");
			}
			ordersService.manual(orders, getCurrentOperator());
			redirectionUrl = "orders!ordersList.htm";
			return "success";
		} catch (Exception e) {
			addActionError(e.getMessage());
			return ordersList();
		}
	}

	public String delete() {
		try {
			ordersService.delete(orders, getCurrentOperator());
			redirectionUrl = "orders!ordersList.htm";
			return "success";
		} catch (Exception e) {
			addActionError(e.getMessage());
			return ordersList();
		}
	}

	public Pagination<Orders> getPage() {
		return page;
	}

	public OrdersQuery getOrdersQuery() {
		return ordersQuery;
	}

	public void setOrdersQuery(OrdersQuery ordersQuery) {
		this.ordersQuery = ordersQuery;
	}

	public void setOrders(Orders orders) {
		this.orders = orders;
	}

	public Orders getOrders() {
		return orders;
	}

	public void setEditPay(Boolean editPay) {
		this.editPay = editPay;
	}

	public Boolean getEditPay() {
		return editPay;
	}
}
